package com.mulder.study.netty.server;

import org.apache.log4j.Logger;
import org.jboss.netty.channel.ChannelEvent;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ChildChannelStateEvent;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelHandler;
import org.jboss.netty.channel.WriteCompletionEvent;


public abstract class MulderNettyCommonServerHandler extends SimpleChannelHandler {
	private static Logger logger = Logger.getLogger(MulderNettyCommonServerHandler.class);
	
	public static final String[] HTTP_SVR_HEADERS = {
	        //"Content-Type: text/html; charset=utf-8",
	          "Connection: close"
	        , "Pragma: no-cache"
	        , "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
	        , "Expires: Thu, 19 Nov 1981 08:52:00 GMT"
	        , "Server: Netty-mulder-test-server-v0.1"
	    };
	    
	
	public abstract void startupAction(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception;

	@Override
	public void bindRequested(ChannelHandlerContext ctx, ChannelStateEvent e)
			throws Exception {
		logger.debug("bindRequested");
		super.bindRequested(ctx, e);
	}

	@Override
	public void channelBound(ChannelHandlerContext ctx, ChannelStateEvent e)
			throws Exception {
		logger.debug("channelBound");
		super.channelBound(ctx, e);
	}

	@Override
	public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e)
			throws Exception {
		logger.debug("channelClosed");
		super.channelClosed(ctx, e);
	}

	@Override
	public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e)
			throws Exception {
		logger.debug("channelConnected");
		super.channelConnected(ctx, e);
		
		 startupAction( ctx,  e) ;
	}

	@Override
	public void channelDisconnected(ChannelHandlerContext ctx,
			ChannelStateEvent e) throws Exception {
		logger.debug("channelDisconnected");
		super.channelDisconnected(ctx, e);
	}

	@Override
	public void channelInterestChanged(ChannelHandlerContext ctx,
			ChannelStateEvent e) throws Exception {
		logger.debug("channelInterestChanged");
		super.channelInterestChanged(ctx, e);
	}

	@Override
	public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
			throws Exception {
		logger.debug("channelOpen");
		super.channelOpen(ctx, e);
	}

	@Override
	public void channelUnbound(ChannelHandlerContext ctx, ChannelStateEvent e)
			throws Exception {
		logger.debug("channelUnbound");
		super.channelUnbound(ctx, e);
	}

	@Override
	public void childChannelClosed(ChannelHandlerContext ctx,
			ChildChannelStateEvent e) throws Exception {
		logger.debug("childChannelClosed");
		super.childChannelClosed(ctx, e);
	}

	@Override
	public void childChannelOpen(ChannelHandlerContext ctx,
			ChildChannelStateEvent e) throws Exception {
		logger.debug("childChannelOpen");
		super.childChannelOpen(ctx, e);
	}

	@Override
	public void closeRequested(ChannelHandlerContext ctx, ChannelStateEvent e)
			throws Exception {
		logger.debug("closeRequested");
		super.closeRequested(ctx, e);
	}

	@Override
	public void connectRequested(ChannelHandlerContext ctx, ChannelStateEvent e)
			throws Exception {
		logger.debug("connectRequested");
		super.connectRequested(ctx, e);
	}

	@Override
	public void disconnectRequested(ChannelHandlerContext ctx,
			ChannelStateEvent e) throws Exception {
		logger.debug("disconnectRequested");
		super.disconnectRequested(ctx, e);
	}

	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
			throws Exception {
		logger.debug("exceptionCaught");
		super.exceptionCaught(ctx, e);
	}

	@Override
	public void handleDownstream(ChannelHandlerContext arg0, ChannelEvent arg1)
			throws Exception {
		logger.debug("handleDownstream");
		super.handleDownstream(arg0, arg1);
	}

	@Override
	public void handleUpstream(ChannelHandlerContext arg0, ChannelEvent arg1)
			throws Exception {
		logger.debug("handleUpstream");
		super.handleUpstream(arg0, arg1);
	}

	@Override
	public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
			throws Exception {
		logger.debug("messageReceived");
		super.messageReceived(ctx, e);
	}

	@Override
	public void setInterestOpsRequested(ChannelHandlerContext ctx,
			ChannelStateEvent e) throws Exception {
		logger.debug("setInterestOpsRequested");		
		super.setInterestOpsRequested(ctx, e);
	}

	@Override
	public void unbindRequested(ChannelHandlerContext ctx, ChannelStateEvent e)
			throws Exception {
		logger.debug("unbindRequested");		
		super.unbindRequested(ctx, e);
	}

	@Override
	public void writeComplete(ChannelHandlerContext ctx, WriteCompletionEvent e)
			throws Exception {
		logger.debug("writeComplete");		
		super.writeComplete(ctx, e);
	}

	@Override
	public void writeRequested(ChannelHandlerContext ctx, MessageEvent e)
			throws Exception {
		logger.debug("writeRequested");
		super.writeRequested(ctx, e);
	}

}
